<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Builder;

class AgentReward extends Base
{
    /**
     * 状态: 待审核
     */
    const STATUS_PENDING_REVIEW = 1;

    /**
     * 状态: 已通过
     */
    const STATUS_PASSED = 2;

    /**
     * 状态: 已驳回
     */
    const STATUS_REJECTED = 3;

    /**
     * 状态: 已撤销
     */
    const STATUS_REVOKED = 4;

    /**
     * 状态: 已追回 (钱给了后再撤销)
     */
    const STATUS_RECOVERED = 5;

    /**
     * 类型: 充值
     */
    const TYPE_TOP_UP = 1;

    /**
     * 类型: 每日下单奖励
     */
    const TYPE_DAILY_ORDER_REWARD = 2;

    /**
     * 类型: 每月下单奖励
     */
    const TYPE_MONTHLY_ORDER_REWARD = 3;

    protected $casts = [
        'created_at' => 'datetime:Y-m-d H:i:s',
        'updated_at' => 'datetime:Y-m-d H:i:s',
        'reward_setting_snapshot' => 'array',
    ];

    public function source()
    {
        return $this->morphTo();
    }

    public function agent()
    {
        return $this->belongsTo(Agent::class);
    }

    /**
     * 有效的
     */
    public function scopeEffective($query)
    {
        return $query->whereIn('status', [self::STATUS_PENDING_REVIEW, self::STATUS_PASSED]);
    }
}
